package cn.just.dao;

import cn.just.entity.Link;
import cn.just.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wujiaming
 */
public class LinkDao {
    public List<Link> findAll() throws SQLException {
        ArrayList<Link> links = new ArrayList<Link>();
        Connection connect = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        connect = JDBCUtil.getConnect();
        String sql = "select title,address from link";

        preparedStatement = connect.prepareStatement(sql);
        resultSet = preparedStatement.executeQuery();
        while(resultSet.next()){
            String title = resultSet.getString("title");
            String address = resultSet.getString("address");

            Link link = new Link(title,address);
            links.add(link);

        }
        JDBCUtil.close(connect,preparedStatement,resultSet);
        return links;
    }


}
